<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../org/angular.min.js"></script>
</head>
<body ng-app='ctrl'>
    <div>
      商品详情：{{ goods.data.title }}<br/>
      价格： {{ goods.data.price }}<br/>
      数量：{{ goods.data.num }}件<br/>
      总计： {{ goods.data.price*goods.data.num }}元<br/>

      <button ng-click='goods.add()'>增加</button>
      <button ng-click='goods.reduce()'></button>
    </div>
    <script>
       var m = angular.module('hd',[]);
       m.controller('ctrl',['$scope',function($scope){
            $scope.goods = {
                data: {
                    'title':'apple mac',
                    'price': 3000,
                    'num': 0
                },
                add: function(){
                    $scope.goods.data.num = Math.min(++$scope.goods.data.num,6)
                },
                reduce: function(){
                    $scope.goods.data.num = Math.max(--$scope.goods.data.num,0)
                }
            }
       }])
    </script>
</body>
</html>